<!--
 * @Descripttion: 车辆作业报表
 * @version: 
 * @Author: ada.wu
 * @Date: 2025-06-25 23:48:14
 * @LastEditors: ada.wu
 * @LastEditTime: 2025-07-09 17:50:42
-->
<style>
    .top-panel>.layui-card-body {
        height: 130px;
    }

    .date-input {
        width: 200px;
    }
</style>
<div class="layuimini-container layuimini-page-anim">
    <!-- 用于创建子页面 -->
    <div class="page-create"></div>

    <!-- page-main-create -->
    <!-- 用于显示 隐藏 -->
    <div class="layuimini-main page-main-create">

        <div class="title-row layuimini-title ">
            <div class="title-left">
                <div class="flex items-center">
                    <h4><span>车辆作业报表</span></h4>
                    <input type="text" name="datePeriodStart" autocomplete="off" id="date_period"
                        class="layui-input date-input ml-3" placeholder="请选择" />
                </div>
            </div>
            <div class="title-right">
                <span class="title-right-text">
                    <button type="button" class="layui-btn  layui-btn-sm layui-btn-primary ml-3"
                        lay-on="download">导出</button>
                </span>
            </div>
        </div>


        <div class="m-df">
            <form class="layui-form" action="" lay-filter="search-form">
                <div class="layui-form-item">
                    <div class="search-box-wrapper">
                        <div class="search-box-body">
                            <div class="layui-inline">
                                <label class="layui-form-label">关联业务</label>
                                <div class="layui-input-inline">
                                    <select class="layui-input" lay-append-to="body" placeholder="请选择"
                                        name="businessNames" lay-search>
                                        <option value="1">清扫保洁</option>
                                        <option value="2">绿化养护</option>
                                        <option value="3">设施维护</option>
                                        <option value="4">其他</option>
                                    </select>
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">所属组织</label>
                                <div class="layui-input-inline">
                                    <select class="layui-input" lay-append-to="body" placeholder="请选择"
                                        name="businessNames" lay-search>
                                        <option value="1">清扫保洁</option>
                                        <option value="2">绿化养护</option>
                                        <option value="3">设施维护</option>
                                        <option value="4">其他</option>
                                    </select>
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">关联网格</label>
                                <div class="layui-input-inline">
                                    <select class="layui-input" lay-append-to="body" placeholder="请选择"
                                        name="businessNames" lay-search>
                                        <option value="1">清扫保洁</option>
                                        <option value="2">绿化养护</option>
                                        <option value="3">设施维护</option>
                                        <option value="4">其他</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="search-box-btns">
                            <button type="submit" class="layui-btn layui-btn-sm" lay-submit
                                lay-filter="data-search-btn">查询</button>
                            <button type="reset" class="layui-btn  layui-btn-sm layui-btn-primary">重置</button>
                        </div>
                    </div>
                </div>
            </form>
        </div>
        <div class="section">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-xs12 layui-col-sm6 layui-col-md3">
                    <div class="layui-card top-panel noborder">
                        <div class="layui-card-header font-weight">
                            <div class="flex-between">
                                <div>
                                    <span lay-on="work_completion">排班率</span>
                                    <i class="layui-icon layui-icon-tips layui-font-gray" lay-on="question_tips"></i>
                                </div>
                                <div lay-on="work_completion">
                                    <span class="layui-icon layui-icon-right layui-font-gray layui-font-14"></span>
                                </div>
                            </div>
                        </div>
                        <div class="layui-card-body" lay-on="work_completion">
                            <div class="layui-row layui-col-space5 flex-center">
                                <div class="layui-col-xs5">
                                    <div class="top-panel-content justify-center">
                                        <div class="outer-circle">
                                            <div class="progress-circle">
                                                <div id="scheduling_rate" class="pie-chart"></div>
                                            </div>
                                            <div class="process-format">
                                                <text id="scheduling_rate_text">0</text>
                                                <span>%</span>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="layui-col-xs7">
                                    <div class="flex justify-center flex-1">
                                        <div class="t-c">
                                            <div class="layui-font-gray">有效排班车(天)</div>
                                            <div class="layui-font-black">0</div>
                                        </div>
                                        <div class="layui-font-gray pl-4 pr-4">/</div>
                                        <div class="t-c">
                                            <div class="layui-font-gray">总车(天)</div>
                                            <div class="layui-font-black">0</div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-col-xs12 layui-col-sm6 layui-col-md3">
                    <div class="layui-card top-panel noborder">
                        <div class="layui-card-header font-weight">
                            <div class="flex-between">
                                <div>
                                    <span lay-on="work_coverage">出勤率</span>
                                    <i class="layui-icon layui-icon-tips layui-font-gray" lay-on="question_tips1"></i>
                                </div>
                                <div lay-on="work_coverage">
                                    <span class="layui-icon layui-icon-right layui-font-gray layui-font-14"></span>
                                </div>
                            </div>
                        </div>
                        <div class="layui-card-body" lay-on="work_coverage">
                            <div class="layui-row layui-col-space5 flex-center">
                                <div class="layui-col-xs5">
                                    <div class="top-panel-content justify-center">
                                        <div class="outer-circle">
                                            <div class="progress-circle">
                                                <div id="attendance_rate" class="pie-chart"></div>
                                            </div>
                                            <div class="process-format">
                                                <text id="attendance_rate_text">0</text>
                                                <span>%</span>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="layui-col-xs7">
                                    <div class="flex justify-center flex-1">
                                        <div class="t-c">
                                            <div class="layui-font-gray">作业车(天)</div>
                                            <div class="layui-font-black">0</div>
                                        </div>
                                        <div class="layui-font-gray pl-4 pr-4">/</div>
                                        <div class="t-c">
                                            <div class="layui-font-gray">已排班车(天)</div>
                                            <div class="layui-font-black">0</div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-col-xs12 layui-col-sm6 layui-col-md3">
                    <div class="layui-card top-panel noborder" lay-on="work_rate">
                        <div class="layui-card-header font-weight">
                            <div class="flex-between ">
                                <div>作业完成率</div>
                                <div>
                                    <span class="layui-icon layui-icon-right layui-font-gray layui-font-14"></span>
                                </div>
                            </div>
                        </div>
                        <div class="layui-card-body">
                            <div class="layui-row layui-col-space5 flex-center">
                                <div class="layui-col-xs5">
                                    <div class="top-panel-content justify-center">
                                        <div class="outer-circle">
                                            <div class="progress-circle">
                                                <div id="work_rate" class="pie-chart"></div>
                                            </div>
                                            <div class="process-format">
                                                <text id="work_rate_text">0</text>
                                                <span>%</span>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="layui-col-xs7">
                                    <div class="flex justify-center flex-1">
                                        <div class="t-c">
                                            <div class="layui-font-gray">实际作业数</div>
                                            <div class="layui-font-black">0</div>
                                        </div>
                                        <div class="layui-font-gray pl-4 pr-4">/</div>
                                        <div class="t-c">
                                            <div class="layui-font-gray">排班作业数</div>
                                            <div class="layui-font-black">0</div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-col-xs12 layui-col-sm6 layui-col-md3">
                    <div class="layui-card top-panel noborder" lay-on="fugai_rate">
                        <div class="layui-card-header font-weight">
                            <div class="flex-between ">
                                <div>作业覆盖率</div>
                                <div>
                                    <span class="layui-icon layui-icon-right layui-font-gray layui-font-14"></span>
                                </div>
                            </div>
                        </div>
                        <div class="layui-card-body">
                            <div class="layui-row layui-col-space5 flex-center">
                                <div class="layui-col-xs5">
                                    <div class="top-panel-content justify-center">
                                        <div class="outer-circle">
                                            <div class="progress-circle">
                                                <div id="fugai_rate" class="pie-chart"></div>
                                            </div>
                                            <div class="process-format">
                                                <text id="fugai_rate_text">0</text>
                                                <span>%</span>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="layui-col-xs7">

                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="title-row px-5">
            <div class="title-left">
                <div class="title-info">
                    <div class="title-line"></div>
                    <span class="title-text">车辆作业数据</span>
                </div>
            </div>
            <div class="title-right" style="flex: auto;">
                <span class="title-right-text">
                    <form class="layui-form" action="" lay-filter="search-form">
                        <div class="layui-form-item mb-0 ">
                            <div class="layui-inline">
                                <label class="layui-form-label">车牌号</label>
                                <div class="layui-input-inline">
                                    <input type="text" placeholder="请输入" name="name" autocomplete="off"
                                        class="layui-input">
                                </div>
                            </div>

                            <div class="layui-inline">
                                <label class="layui-form-label">车辆类型</label>
                                <div class="layui-input-inline">
                                    <select class="layui-input" lay-append-to="body" placeholder="请选择"
                                        name="businessNames" lay-search>
                                        <option value="1">清扫保洁</option>
                                        <option value="2">绿化养护</option>
                                        <option value="3">设施维护</option>
                                        <option value="4">其他</option>
                                    </select>
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">作业路段</label>
                                <div class="layui-input-inline">
                                    <select class="layui-input" lay-append-to="body" placeholder="请选择"
                                        name="businessNames" lay-search>
                                        <option value="1">清扫保洁</option>
                                        <option value="2">绿化养护</option>
                                        <option value="3">设施维护</option>
                                        <option value="4">其他</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                    </form>


                </span>
            </div>
        </div>
        <div class="px-5">
            <span class="layui-font-gray pr-5">计划作业里程：55.54公里</span>
            <span class="layui-font-gray pr-5">实际作业里程：45.54公里</span>
        </div>
        <div class="px-5  table-stripe">
            <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
        </div>
        <script type="text/html" id="currentTableBar">
            <a class="layui-font-blue mr-3" lay-event="detail">详情</a>
        </script>
    </div>
</div>
<script>
    layui.use(['form', 'table', 'miniPage', 'echarts'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            laydate = layui.laydate,
            layer = layui.layer,
            util = layui.util,
            echarts = layui.echarts,
            miniPage = layui.miniPage;
        function updatePieChart(elementId, percent, textId = null) {
            const chart = echarts.init(document.getElementById(elementId));
            if (!chart) return;

            if (textId) {
                const textDom = document.getElementById(textId);
                if (textDom) {
                    textDom.innerText = percent;
                }
            }

            var option = {
                series: [{
                    type: 'pie',
                    radius: ['80%', '100%'],
                    label: {
                        show: false,
                    },
                    data: [
                        { value: percent, name: '排班率', itemStyle: { color: '#0080FF' } },
                        { value: 100 - percent, name: '未完成', itemStyle: { color: '#e0e0e0' } }
                    ],
                    hoverAnimation: false,
                    labelLine: {
                        show: false
                    }
                }]
            };
            chart.setOption(option);
            window.onresize = function () {
                chart.resize();
            }
        }

        updatePieChart('scheduling_rate', 15, 'scheduling_rate_text');
        updatePieChart('attendance_rate', 75, 'attendance_rate_text');
        updatePieChart('work_rate', 75, 'work_rate_text');
        updatePieChart('fugai_rate', 75, 'fugai_rate_text');
        /******************** 渲染组件 start ********************/
        form.render('select'); //刷新select选择框渲染
        // 起始日期
        laydate.render({
            elem: '#date_period',
            range: true
        });
        function setWorkDetailPage(pageType) {
            layui.sessionData('CAR_WORK_DETAIL_PARAMS', { key: 'pageType', value: pageType });
            try {
                miniPage.renderPageCreate(`page/mechanicalWork/carWorkList/components/carWorkDetail.html`)
            } catch (e) {
                console.error("页面加载失败：", e);
                // 可根据项目实际情况弹窗提示用户
            }
        }
        util.on('lay-on', {
            //pageType 0 排班详情 1 出勤详情 2 考勤详情 3 覆盖率详情
            'work_completion': function () {//排班详情
                setWorkDetailPage("0")
            },
            'work_coverage': function () {//出勤详情
                setWorkDetailPage("1")
            },
            'work_rate': function () {//考勤详情
                setWorkDetailPage("2")
            },
            'fugai_rate': function () {//覆盖率详情
                setWorkDetailPage("3")
            },
            'question_tips': function () {
                layer.tips(`<p class="layui-font-14 layui-font-black"> 排班率 = 有效排班车(天) / 总车(天)</p>
                            <p class="layui-font-14 layui-font-black">有效排班车(天)：每日、每辆正常状态的车辆排班计1车(天),</p>
                            <p class="layui-font-14 layui-font-black">总车(天)：单日内每辆正常状态的车辆计1车(天)</p>
                            <p class="layui-font-gray">*每日故障、备用状态的车辆不纳入上述两项统计</p>`, this, {
                    tips: [1, '#ffffff'],
                    area: ['420px', 'auto']
                });
            },
            'question_tips1': function () {
                layer.tips(`<p class="layui-font-14 layui-font-black"> 已生成的故障或备用车辆的作业任务，会计入考勤率</p>
                            `, this, {
                    tips: [1, '#ffffff'],
                    area: ['420px', 'auto']
                });
            },
        })


        /******************** 渲染组件 end ********************/



        table.render({
            elem: '#currentTableId',
            url: 'api/table.json',
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter'],
            cols: [[

                { field: 'name', minWidth: 180, title: '车辆' },
                { field: 'name', minWidth: 100, title: '出勤率', sort: true },
                { field: 'name', minWidth: 100, title: '实际出勤(天)' },
                { field: 'name', minWidth: 100, title: '应出勤(天)' },
                { field: 'name', minWidth: 180, title: '总行驶里程(公里)', sort: true },
                { field: 'name', minWidth: 180, title: '计划作业次数/里程' },
                { field: 'name', minWidth: 180, title: '实际作业次数/里程' },
                { field: 'name', minWidth: 180, title: '作业覆盖率', sort: true },
                { field: 'name', minWidth: 100, title: '计划任务数' },
                { field: 'name', minWidth: 100, title: '作业任务数' },
                { field: 'name', minWidth: 100, title: '所属组织' },
                { field: 'name', minWidth: 100, title: '业务类型' },
                { field: 'name', minWidth: 100, title: '关联网格' },

                { title: '操作', minWidth: 100, toolbar: '#currentTableBar', align: "center" }
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 10,
            page: true,
            skin: 'grid',
            size: 'lg'
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            var result = JSON.stringify(data.field);
            layer.alert(result, {
                title: '最终的搜索信息'
            });

            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: {
                    searchParams: result
                }
            }, 'data');

            return false;
        });


        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'detail') {  // 监听详情操作
                miniPage.renderPageCreate(`page/mechanicalWork/carWorkList/components/carWorkDetail.html?id=${data.id}`)
            }
        });

    });



</script>